package com.rapwaves.mc.server;

import java.util.List;

import org.gwtwidgets.server.spring.GWTSpringController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import com.oauth.logging.OAuthLogger;
import com.rapwaves.mc.client.beans.SiteDetailsBean;
import com.rapwaves.mc.client.rpc.MembercareRemoteService;
import com.rapwaves.mc.server.service.MembercareService;

public class MembercareGwtController extends GWTSpringController implements MembercareRemoteService {

	private OAuthLogger logger = OAuthLogger.getLogger(this.getClass());

	private static final long serialVersionUID = -5758464341967618224L;

	@Autowired
	private MembercareService membercareService;

	@Autowired
	@Value("${mc.newusers.interval}")
	private int interval;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.rapwaves.mc.client.rpc.MembercareRemoteService#getSiteDetails()
	 */
	@Override
	public SiteDetailsBean getSiteDetails() {
		Long totalUsers = membercareService.getCount();
		List<String> newUsers = membercareService.getNewUsers(interval);
		List<String> activeUsers = membercareService.getActiveUsers(interval);
		SiteDetailsBean bean = new SiteDetailsBean(totalUsers, activeUsers, newUsers);
		return bean;
	}

}
